const state = {
	societyInfo:{},
	allSocietys:[],
	requestList:[]
}
const mutations = {
	SET_SOCIETYINFO(state,info){
		state.societyInfo = info;
	},
	SET_ALLSOCIETYS(state,data){
		state.allSocietys = data;
	},
	SET_REQUESTLIST(state,list){
		state.requestList = list;
	}
}

const actions = {
	// 根据id获取社团信息
	async getSocietyInfo({commit},society_id){
		let {data} = await uni.$u.http.get('/society/getSocietyInfo',{params:{society_id}});
		if(data.code === 200){
			commit('SET_SOCIETYINFO',data.society);
		}
		return data.code;
	},
	async quitSociety({commit},user_id){
		let {data} = await uni.$u.http.get('/society/quit',{params:{user_id}});
		return data.code;
	},
	// 获取全部社团
	async getAllSocietys({commit}){
		let {data} = await uni.$u.http.get('/society/getInfo',{params:{pageNo:1, limit:999}});
		if(data.code === 200){
			commit('SET_ALLSOCIETYS',data.data.rows);
		}
	},
	// 我的申请
	async getMyRequest({commit},user_id){
		let {data} = await uni.$u.http.get('/society/join/history',{params:{user_id}});
		if(data.code === 200){
			commit('SET_REQUESTLIST',data.list)
		}
	}
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
